<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>The EventBase class</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="event.timer.html">« Event::timer</a></li>
      <li style="float: right;"><a href="eventbase.construct.html">EventBase::__construct »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="book.event.html">Event</a></li>
    <li>The EventBase class</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="class.eventbase" class="reference">
 <h1 class="title">The EventBase class</h1>
 
 <div class="partintro"><p class="verinfo">(PECL event &gt;= 1.2.6-beta)</p>

  <div class="section" id="eventbase.intro">
   <h2 class="title">简介</h2>
   <p class="para">
    <span class="classname"><strong class="classname">EventBase</strong></span>
    class represents libevent&#039;s event base structure. It holds a set of events
    and can poll to determine which events are active.
   </p>
   <p class="para">
    Each event base has a
    <em class="emphasis">method</em>
    , or a
    <em class="emphasis">backend</em>
    that it uses to determine which events are ready. The recognized methods
    are:
    <code class="literal">select</code>
    ,
    <code class="literal">poll</code>
    ,
    <code class="literal">epoll</code>
    ,
    <code class="literal">kqueue</code>
    ,
    <code class="literal">devpoll</code>
    ,
    <code class="literal">evport</code>
    and
    <code class="literal">win32</code>
    .
   </p>
   <p class="para">
    To configure event base to use, or avoid specific backend
    <span class="classname"><a href="class.eventconfig.html" class="classname">EventConfig</a></span>
    class can be used.
   </p>
   <div class="warning"><strong class="warning">警告</strong>
    <p class="para">
     Do
     <em class="emphasis">NOT</em>
     destroy the
     <span class="classname"><strong class="classname">EventBase</strong></span>
     object as long as resources of the associated
     <code class="literal">Event</code>
     objects are not released. Otherwise, it will lead to unpredictable
     results!
    </p>
   </div>
  </div>

  <div class="section" id="eventbase.synopsis">
   <h2 class="title">类摘要</h2>


   <div class="classsynopsis">
    <div class="ooclass">
     
    </div>

    <div class="classsynopsisinfo">
     <span class="ooclass">
      <span class="modifier">final</span>
      <span class="modifier">class</span> <strong class="classname">EventBase</strong>
     </span>
     {</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* Constants */</div>
    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.eventbase.html#eventbase.constants.loop-once"><var class="varname">LOOP_ONCE</var></a></var><span class="initializer"> = 1</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.eventbase.html#eventbase.constants.loop-nonblock"><var class="varname">LOOP_NONBLOCK</var></a></var><span class="initializer"> = 2</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.eventbase.html#eventbase.constants.nolock"><var class="varname">NOLOCK</var></a></var><span class="initializer"> = 1</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.eventbase.html#eventbase.constants.startup-iocp"><var class="varname">STARTUP_IOCP</var></a></var><span class="initializer"> = 4</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.eventbase.html#eventbase.constants.no-cache-time"><var class="varname">NO_CACHE_TIME</var></a></var><span class="initializer"> = 8</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.eventbase.html#eventbase.constants.epoll-use-changelist"><var class="varname">EPOLL_USE_CHANGELIST</var></a></var><span class="initializer"> = 16</span>;</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 方法 */</div>
    <div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="methodname"><a href="eventbase.construct.html" class="methodname">__construct</a></span>(<span class="methodparam">
    <span class="type"><a href="class.eventconfig.html" class="type EventConfig">EventConfig</a></span>
     <code class="parameter">$cfg</code>
   <span class="initializer"> = ?</span></span>)</div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span>
   <span class="methodname"><a href="eventbase.dispatch.html" class="methodname">dispatch</a></span>(): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span>
   <span class="methodname"><a href="eventbase.exit.html" class="methodname">exit</a></span>(<span class="methodparam">
    <span class="type">float</span>
     <code class="parameter">$timeout</code>
   <span class="initializer"> = ?</span></span>): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span>
   <span class="methodname"><a href="eventbase.free.html" class="methodname">free</a></span>(): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span>
   <span class="methodname"><a href="eventbase.getfeatures.html" class="methodname">getFeatures</a></span>(): <span class="type">int</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span>
   <span class="methodname"><a href="eventbase.getmethod.html" class="methodname">getMethod</a></span>(): <span class="type">string</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span>
   <span class="methodname"><a href="eventbase.gettimeofdaycached.html" class="methodname">getTimeOfDayCached</a></span>(): <span class="type">float</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span>
   <span class="methodname"><a href="eventbase.gotexit.html" class="methodname">gotExit</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span>
   <span class="methodname"><a href="eventbase.gotstop.html" class="methodname">gotStop</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span>
   <span class="methodname"><a href="eventbase.loop.html" class="methodname">loop</a></span>(<span class="methodparam">
    <span class="type">int</span>
     <code class="parameter">$flags</code>
   <span class="initializer"> = ?</span></span>): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span>
   <span class="methodname"><a href="eventbase.priorityinit.html" class="methodname">priorityInit</a></span>(<span class="methodparam">
    <span class="type">int</span>
     <code class="parameter">$n_priorities</code>
   </span>): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span>
   <span class="methodname"><a href="eventbase.reinit.html" class="methodname">reInit</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span>
   <span class="methodname"><a href="eventbase.stop.html" class="methodname">stop</a></span>(): <span class="type">bool</span></div>

   }</div>

  </div>

  <div class="section" id="eventbase.constants">
   <h2 class="title">预定义常量</h2>
   <dl>
    
     <dt id="eventbase.constants.loop-once">
      <strong><code>EventBase::LOOP_ONCE</code></strong>
     </dt>

     <dd>

      <p class="para">
       Flag used with
       <span class="methodname"><a href="eventbase.loop.html" class="methodname">EventBase::loop()</a></span>
       method which means: &quot;block until libevent has an active event, then
       exit once all active events have had their callbacks run&quot;.
      </p>
     </dd>

    
    
     <dt id="eventbase.constants.loop-nonblock">
      <strong><code>EventBase::LOOP_NONBLOCK</code></strong>
     </dt>

     <dd>

      <p class="para">
       Flag used with
       <span class="methodname"><a href="eventbase.loop.html" class="methodname">EventBase::loop()</a></span>
       method which means: &quot;do not block: see which events are ready now, run
       the callbacks of the highest-priority ones, then exit&quot;.
      </p>
     </dd>

    
    
     <dt id="eventbase.constants.nolock">
      <strong><code>EventBase::NOLOCK</code></strong>
     </dt>

     <dd>

      <p class="para">
       Configuration flag. Do not allocate a lock for the event base, even if
       we have locking set up&quot;.
      </p>
     </dd>

    
    
     <dt id="eventbase.constants.startup-iocp">
      <strong><code>EventBase::STARTUP_IOCP</code></strong>
     </dt>

     <dd>

      <p class="para">
       Windows-only configuration flag. Enables the IOCP dispatcher at
       startup.
      </p>
     </dd>

    
    
     <dt id="eventbase.constants.no-cache-time">
      <strong><code>EventBase::NO_CACHE_TIME</code></strong>
     </dt>

     <dd>

      <p class="para">
       Configuration flag. Instead of checking the current time every time the
       event loop is ready to run timeout callbacks, check after each timeout
       callback.
      </p>
     </dd>

    
    
     <dt id="eventbase.constants.epoll-use-changelist">
      <strong><code>EventBase::EPOLL_USE_CHANGELIST</code></strong>
     </dt>

     <dd>

      <p class="para">
       If we are using the
       <code class="literal">epoll</code>
       backend, this flag says that it is safe to use Libevent&#039;s internal
       change-list code to batch up adds and deletes in order to try to do as
       few syscalls as possible.
      </p>
      <p class="para">
       Setting this flag can make code run faster, but it may trigger a Linux
       bug: it is not safe to use this flag if one has any fds cloned by
       dup(), or its variants. Doing so will produce strange and
       hard-to-diagnose bugs.
      </p>
      <p class="para">
       This flag can also be activated by settnig the
       <code class="literal">EVENT_EPOLL_USE_CHANGELIST</code>
       environment variable.
      </p>
      <p class="para">
       This flag has no effect if one winds up using a backend other than
       <code class="literal">epoll</code>
       .
      </p>
     </dd>

    
   </dl>

  </div>

 </div>

 



































































<h2>目录</h2><ul class="chunklist chunklist_reference"><li><a href="eventbase.construct.html">EventBase::__construct</a> — 构造 EventBase 对象</li><li><a href="eventbase.dispatch.html">EventBase::dispatch</a> — Dispatch pending events</li><li><a href="eventbase.exit.html">EventBase::exit</a> — Stop dispatching events</li><li><a href="eventbase.free.html">EventBase::free</a> — Free resources allocated for this event base</li><li><a href="eventbase.getfeatures.html">EventBase::getFeatures</a> — Returns bitmask of features supported</li><li><a href="eventbase.getmethod.html">EventBase::getMethod</a> — Returns event method in use</li><li><a href="eventbase.gettimeofdaycached.html">EventBase::getTimeOfDayCached</a> — Returns the current event base time</li><li><a href="eventbase.gotexit.html">EventBase::gotExit</a> — Checks if the event loop was told to exit</li><li><a href="eventbase.gotstop.html">EventBase::gotStop</a> — Checks if the event loop was told to exit</li><li><a href="eventbase.loop.html">EventBase::loop</a> — Dispatch pending events</li><li><a href="eventbase.priorityinit.html">EventBase::priorityInit</a> — Sets number of priorities per event base</li><li><a href="eventbase.reinit.html">EventBase::reInit</a> — Re-initialize event base(after a fork)</li><li><a href="eventbase.stop.html">EventBase::stop</a> — Tells event_base to stop dispatching events</li></ul>
</div>
</div></div></body></html>